<template>
	<view class="pages">
		<view class="pages-details">
			<view class="pages-details-cotent">
				<view class="pages-list-item" v-if="loading">
					<up-skeleton
						loading
						rows="5"
						title
						animate
					></up-skeleton>
				</view>
				<view class="pages-list-item" style="background-color: #fff;" v-if="!loading">
					<view 
						class="pages-item-status"
						:class="{
							'pages-item-status--warning' : details.taskStatus == 0,
							'pages-item-status--success':  details.taskStatus == 1
						}"
					>
						{{ details.taskStatus == 0 ? '待分拨' : details.taskStatus == 1 ? '已分拨' : details.taskStatus == 2 ? '已完成' : '待分拨' }}
					</view>
					
					<view class="pages-item-title">
						<text>{{ details.taskName || '--' }}</text>
						<text class="pages-item-title--tag" v-show="details.overdue == 1">逾期</text>
					</view>
					
					
					<view class="pages-item-row">
						<text class="pages-hint-title">任务发起人</text>
						<view class="pages-hint-content pages-hint-content--active" @click="onCallPerson">
							<up-icon 
								name="phone" 
								color="#2979ff" 
								labelColor="#2979ff"
								size="32rpx"
								label="曾文勇/福田街道办"
								labelSize="28rpx"
							></up-icon>
						</view>
					</view>
					
					<view class="pages-item-row">
						<text class="pages-hint-title">任务板块</text>
						<text class="pages-hint-content">场所巡查</text>
					</view>
					
					<view class="pages-item-row">
						<text class="pages-hint-title">场所类型</text>
						<text class="pages-hint-content">公益广告宣传（一周一次）</text>
					</view>
					
					<view class="pages-item-row">
						<text class="pages-hint-title">发布时间</text>
						<text class="pages-hint-content">{{ details.createTime || details.startDate || '--' }}</text>
					</view>
					
					<view class="pages-item-row">
						<text class="pages-hint-title">任务时间</text>
						<text class="pages-hint-content">{{ details.startDate || '--' }} 至 {{ details.endDate || '--' }}</text>
					</view>
					<view class="pages-item-row">
						<text class="pages-hint-title">任务进度</text>
						<view class="pages-hint-content pages-hint-content--flex">
							<view style="width: 350rpx;">
								<up-line-progress
									:percentage="(((details.checkNum / details.taskNum) * 100).toFixed(2)) * 1" 
									activeColor="#0F5BFF"
									height="30rpx"
								></up-line-progress>
							</view>
							<text style="margin-left: 10rpx;">{{ `${details.taskNum || 0}/${details.checkNum || 0}` }}</text>
						</view>
					</view>
					
					<view class="pages-item-bolck" v-if="details.taskContent">
						<view class="pages-bolck-title">
							<text class="pages-bolck-title-ad"></text>
							任务内容
						</view>
						<view class="pages-bolck-content">{{ details.taskContent}}</view>
					</view>
					
					<view class="pages-item-bolck" v-if="details.remark">
						<view class="pages-bolck-title">
							<text class="pages-bolck-title-ad"></text>
							备注
						</view>
						<view class="pages-bolck-content">{{ details.remark }}</view>
					</view>
				</view>
			</view>
		</view>
		
		
		<view class="pages-statistics">
			<view class="pages-bolck-title">
				<text class="pages-bolck-title-ad"></text>
				核查进度
				<text class="pages-hint-title" style="width: auto;">共计10条</text>
			</view>
			
			<template v-if="!loading">
				<view class="pages-item" v-for="item of 6" :key="item" @click="onSkipRouterToTaskItem">
					<view class="pages-item-title">
						石厦社区
					</view>
					
					<view class="pages-item-content">
						<view class="pages-content-item">
							<view class="pages-content-item-font">
								188
							</view>
							<view class="pages-content-item-text">
								全部场所
							</view>
						</view>
						<view class="pages-content-item">
							<view class="pages-content-item-font pages-content-item-font--warning">
								188
							</view>
							<view class="pages-content-item-text">
								待巡查
							</view>
						</view>
						<view class="pages-content-item">
							<view class="pages-content-item-font pages-content-item-font--error">
								188
							</view>
							<view class="pages-content-item-text">
								待整改
							</view>
						</view>
						<view class="pages-content-item">
							<view class="pages-content-item-font pages-content-item-font--success">
								188
							</view>
							<view class="pages-content-item-text">
								已完成
							</view>
						</view>
					</view>
					
					<view class="pages-item-row">
						<text class="pages-hint-title">场所巡查率</text>
						<view class="pages-hint-content pages-hint-content--flex">
							<view style="width: 350rpx;">
								<up-line-progress
									:percentage="86" 
									activeColor="#7EBBFF"
									height="30rpx"
								></up-line-progress>
							</view>
							<text style="margin-left: 10rpx;">{{ `${88 || 0}/${66 || 0}` }}</text>
						</view>
					</view>
				</view>
			</template>
			<template v-if="loading">
				<view class="pages-item" v-for="item of 4"  :key="item">
					<up-skeleton
						loading
						rows="3"
						title
						animate
					></up-skeleton>
				</view>
			</template>
			<template v-if="false">
				<up-empty icon="list" marginTop="300rpx"></up-empty>
			</template>
			
			<up-loadmore line loadingIcon="circle" v-show="true" status="nomore" />
		</view>
		
		<view class="pages-buttons--fill"></view>
		<view class="pages-button">
			<up-button 
				color="#2E90EC" 
				text="任务分拨"
				@click="onSkipRouterToAllocate"
			></up-button>
		</view>
	</view>
</template>

<script setup>
import { onLoad, onReachBottom, onPullDownRefresh } from "@dcloudio/uni-app";
import { reactive, ref } from "vue";
import { onHasUserinfoData, onSetUserinfoData, onGetUserinfoData, onGetRoleIdData,  onSetRoleIdData, onSetRolesData, onGetRolesData } from "/common/userinfo.js"
import { onGetTaskDetails } from "/serves/api.js";



const loading = ref(true)
const details = ref({})


const onSkipRouterToAllocate  = () => {
	const url = '/pages/allocate/index'
	uni.navigateTo({ url })
}

const onPageGetTaskDetails = async (options) => {
	const { id } = options
	loading.value = true
	
	try{
		const response = await onGetTaskDetails(id)
		const { data } = response
		const { task } = data
		details.value = task
	} finally {
		loading.value = false
	}
}

const tabs = reactive([
	{ name: '部门任务', value: 'dept' },
	{ name: '个人任务', value: 'user' },
]) 
const types = reactive([
	{ name: '巡查任务', value: 'dept' },
	{ name: '处置任务', value: 'user' },
])

const onCallPerson = function () {
	uni.makePhoneCall({
		phoneNumber: '18664306776',
		success: () => {},
		fail: () => {}
	})
}

const scrolltolower  = function(e) {}

// 切换tabs
const onSkipTabs = function (e) {
	console.log(e)
}

const onSelectOrg = function () {
	selectOrgRef.value.onShowPopup()
}

const onSkipRouterToTaskItem = function () {
	const url = '/pages/task/item'
	uni.navigateTo({ url })
	// uni.navigateBack()
}

onLoad((options) => onPageGetTaskDetails(options))
</script>

<style scoped lang="scss">
.pages-details {
	width: 100%;
	height: auto;
	box-sizing: border-box;
	padding: 30rpx;
	padding-bottom: 0;
	background-image: linear-gradient(180deg, #2E90EC 0%, #F2F2F2 90%);
}

.pages-details-cotent {
	width: 100%;
	height: auto;
	box-sizing: border-box;
	display: flex;
	align-items: center;
	justify-content: space-between;
	
}

.pages-list-item {
	width: 100%;
	height: auto;
	box-shadow: 8rpx 8rpx 16rpx 0px rgba(0,0,0,0.3);
	border-radius: 4rpx;
	box-sizing: border-box;
	padding: 24rpx 30rpx;
	margin-bottom: 30rpx;
	position: relative;
	overflow: hidden;
	transform: all 0.2s;
}

.pages-item-status {
	width: 150rpx;
	height: 150rpx;
	background-color: #317FFC;
	text-align: center;
	font-size: 24rpx;
	color: #FFFFFF;
	box-sizing: border-box;
	padding-top: 110rpx;
	transform: rotate(45deg);
	position: absolute;
	top: -75rpx;
	right: -75rpx;
	box-shadow: 4rpx 4rpx 4rpx 0px rgba(49, 127, 252, .3);
	
	&--warning {
		background-color: #FF9900;
		box-shadow: 4rpx 4rpx 8rpx 0px rgba(255, 153, 0, .3);
	}
	
	&--success {
		background-color: #00C500;
		box-shadow: 4rpx 4rpx 8rpx 0px rgba(0, 197, 0, .3);
	}
}

.pages-item-title {
	font-family: PingFangSC, PingFang SC;
	font-weight: 500;
	font-size: 36rpx;
	color: #171717;
	line-height: 1.5em;
	font-style: normal;
	width: 100%; 
	
	&--tag {
		padding: 5rpx 10rpx;
		font-size: 28rpx;
		color: #FF0000;
		border: 1px solid #FF0000;
		background-color: rgba(255, 0, 0, .1);
		margin-left: 20rpx;
		border-radius: 4rpx;
	}
	
	
}

.pages-item-row {
	width: 100%;
	min-height: 60rpx;
	height: auto;
	box-sizing: border-box;
	padding-top: 10rpx;
	display: flex;
	align-items: flex-start;
}

.pages-hint-title {
	width: 160rpx;
	font-weight: 400;
	font-size: 28rpx;
	color: #666666;
}

.pages-hint-content {
	display: inline-block;
	width: calc(100% - 160rpx);
	font-weight: 500;
	font-size: 28rpx;
	color: #333333;
	transition: all .3s;
	
	&--active {
		padding-top: 5rpx;
		
		&:active {
			opacity: 0.9;
		}
	}
}

.pages-hint-content--flex {
	display: inline-flex;
	align-items: center;
}

.pages-hint-content--hint {
	margin-left: 10rpx;
	font-weight: 400;
	font-size: 28rpx;
	color: #666666;
}

.pages-item-bolck {
	width: 100%;
	height: auto;
}

.pages-bolck-title {
	height: 70rpx;
	display: flex;
	align-items: center;
	font-weight: 500;
	font-size: 30rpx;
	color: #000000;
	box-sizing: border-box;
}

.pages-bolck-title-ad {
	width: 6rpx;
	height: 32rpx;
	background-color: #317FFC;
	border-radius: 3rpx;
	margin-right: 15rpx;
}

.pages-bolck-content {
	width: 100%;
	font-weight: 500;
	font-size: 28rpx;
	color: #333333;
	text-indent: 2em;
	line-height: 1.5em;
}

.pages-statistics {
	width: 100%;
	height: auto;
	box-sizing: border-box;
	padding: 10rpx 30rpx;
	padding-bottom: env(safe-area-inset-bottom);
}

.pages-item  {
	width: 100%;
	height: auto;
	background: linear-gradient(0deg, #FFFFFF 0%, #F6F9FF 100%);
	box-shadow: 8rpx 8rpx 16rpx 0px rgba(0,0,0,0.1);
	border-radius: 4rpx;
	box-sizing: border-box;
	padding: 32rpx;
	margin-bottom: 30rpx;
	transform: all 0.2s;
	
	&:active {
		background: linear-gradient(0deg, #FFFFFF 2%, rgba(126, 187, 255, .2) 100%);
		box-shadow: 8rpx 8rpx 16rpx 0px rgba(0,0,0,0.3);
	}
}

.pages-item-title {
	font-family: PingFangSC, PingFang SC;
	font-weight: 500;
	font-size: 32rpx;
	color: #333333;
	text-shadow: 0px 0px 10rpx rgba(109,114,141,0.17);
	text-align: justify;
	font-style: normal;
}

.pages-item-content {
	width: 100%;
	height: auto;
	box-sizing: border-box;
	padding: 20rpx 0;
	display: flex;
	align-items: center;
	justify-content: space-between;
}


.pages-content-item {
	flex: 1;
	display: flex;
	flex-direction: column;
	align-items: center;
	border-right: 1px solid #F6F6F6;
	
	&:last-child {
		border-right: 0;
	}
}

.pages-content-item-font {
	font-weight: 500;
	font-size: 48rpx;
	color: #317FFC;
	line-height: 1.5em;
	text-shadow: 0px 0px 10rpx rgba(109,114,141,0.17);
	text-align: left;
	font-style: normal;
	
	&--warning {
		color: #FF9900;
	}
	
	&--error {
		color: #FF0000;
	}
	
	&--success {
		color: #00C500;
	}
}

.pages-content-item-text {
	font-family: PingFangSC, PingFang SC;
	font-weight: 400;
	font-size: 28rpx;
	color: #999999;
	line-height: 1.5em;
	text-shadow: 0px 0px 10rpx rgba(109,114,141,0.17);
	text-align: left;
	font-style: normal;
}

.pages-buttons--fill {
	width: 100%;
	height: calc(110rpx + env(safe-area-inset-bottom));
}

.pages-button {
	width: 100%;
	height: calc(110rpx + env(safe-area-inset-bottom));
	box-sizing: border-box;
	padding: 30rpx;
	box-shadow: 0px 2px 8px 0px rgba(0,0,0,0.18);
	position: fixed;
	bottom: 0;
	left: 0;
	z-index: 1;
	display: flex;
	align-items: center;
	justify-content: space-between;
	background-color: #ffffff;
}

</style>